﻿package net.nicoptere.media 
{
	import flash.media.Sound;
	import flash.media.SoundChannel;
	import flash.media.SoundTransform;
	
	/**
	 * @author nicolas barradeau
	 */
	public class SoundManager 
	{
		
		
		static protected var st:SoundTransform = new SoundTransform( .5 );
		static protected var ready:Boolean = false;
		static protected var sounds:Array = [];
		
		/**
		 * 
		 * @param	soundItems
		 */
		public function SoundManager( soundItems:Array = null ) 
		{
			
			if ( soundItems != null )
			{
				//instancie tout le monde
			}
			ready = true;
		}
		
		
		static public function addItem( item:SoundItem ):void
		{
			sounds[ id ] =  item;
		}
		
		static public function play( id:String ):void
		{
			
			if ( !ready )
			{
				new SoundManager();
			}
			
			var item:SoundItem = ( sounds[ id ] as SoundItem );
			var s:Sound = item.sound;
			if ( s != null && item.ready ) s.play( 0, 0, new SoundTransform( item.volume ) );
			
		}
		
		static public function set volume( value:Number ):void
		{
			st.volume = value;
		}
		static public function get volume():Number { return st.volume; }
		
	}
	
}